﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UI;
using DG.Tweening;
using CurvedUI;
using Base.Custom;

public class MainMenuPanel : BasePanel {

    private CanvasGroup canvasGroup;//获取CanvasGroup组件，用于控制该面板的交互功能
    private Transform canvasTransform;//实例化的面板归为它的子物体
    private CurvedUISettings curvedui;//环形UI组件
	private Button hideActivButton;
    private Button displayActivButton;
    private Stack<SingleObject> singleObj;
    // Use this for initialization
    void Awake () {
        singleObj = new Stack<SingleObject>();
        canvasGroup = GetComponent<CanvasGroup>();
        canvasTransform = GameObject.Find("Canvas").transform;
		hideActivButton = transform.Find ("HideActivButton").GetComponent<Button>();
        displayActivButton = transform.Find ("DisplayActivButton").GetComponent<Button>();
        //curvedui = canvasTransform.GetComponent<CurvedUISettings>();
    }

    public override void OnEnter()
    {
        //curvedui.Angle = 1;
        canvasGroup.blocksRaycasts = true;
    }
    public override void OnPause()
    {
        canvasGroup.blocksRaycasts = false;
    }
    public override void OnResume()
    {
        canvasGroup.blocksRaycasts = true;
    }

    // Update is called once per frame
    void Update () {
        
        if (singleObj != null)
        {
            hideActivButton.interactable = true;

        }
        else if (hideActivButton.interactable)
        {
            hideActivButton.interactable = false;
        }
        else if (displayActivButton.interactable)
        {
            displayActivButton.interactable = false;
        }
        if (Input.GetMouseButtonDown(1)&& canvasGroup.blocksRaycasts)
        {
            UIManager.Instance.PushPanel(UI.UIPanelType.对象);
            if (FreeCamera.freecamera.singleobj!=null)
            {
                UIManager.Instance.PopPanel(this);
                if (FreeCamera.freecamera.singleobj.name.Contains("房间"))
                {
                    UIManager.Instance.PushPanel(UI.UIPanelType.模型);
                }
                else
                {
                    UIManager.Instance.PushPanel(UI.UIPanelType.对象);
                }
            }
        }



    }

    public void OnClick(string panelTypeString)
    {
        UIPanelType panelType = (UIPanelType)System.Enum.Parse(typeof(UIPanelType), panelTypeString);
        UIManager.Instance.PopPanel();
        UIManager.Instance.PushPanel(panelType);
    }
	public void yingcang()
	{
		SingleObject sobj = FreeCamera.freecamera.singleobj;
		if (sobj!=null)
		{
			singleObj.Push(sobj);
			sobj.go.SetActive(false);
		}
	}
	public void xianshi()
	{
		if (singleObj.Count!=0)
		{
			SingleObject sobj = singleObj.Pop();
			sobj.go.SetActive(true);
		}
	}
	public void xianshiAll()
	{
		for (int i = singleObj.Count; i >0; i--)
		{
			SingleObject sobj = singleObj.Pop();
			sobj.go.SetActive(true);
		}
	}
}
